/*
 * @Author: wangyu
 * @Date: 2024-11-19 14:08:55
 * @LastEditTime: 2024-12-27 18:23:19
 * @LastEditors: wangyu
 * @Description:
 * @FilePath: \dzsq-smartpark-platform\src\router\index.js
 */
import { createRouter, createWebHashHistory } from "vue-router";
import Routes from "./routes";
import Store from "@/store";
import Cookies from "js-cookie";
import { getRoleKeyItems } from "../apis/common.js";
import { service } from "../axios/index.js";

const routes = Routes;

const router = createRouter({
  history: createWebHashHistory(),
  routes,
});
const goLogin = () => {
  localStorage.clear();
  let LoginURL = import.meta.env.VITE_APP_LOGIN_URL;
  window.location.href = LoginURL;
};
router.beforeEach(async (next, to) => {
  // step 1. 获取token
  // 检查路径中是否有带token
  // 有则直接取用存到localStorage中，然后重定向去掉地址中的token
  // 后续直接从locakStorage中取用token
  // let TOKEN = "";
  // if (to && to.query && to.query.token) {
  //   TOKEN = to.query.token;
  //   delete to.query.token;
  //   localStorage.setItem("token", TOKEN);
  //   router.replace({ path: to.path, query: to.query, params: to.params });
  //   return false;
  // }
  // TOKEN = localStorage.getItem("token");
  // if (!TOKEN) {
  //   goLogin();
  //   return false;
  // }
  // let response = await getRoleKeyItems()
  // if (response && response.data && response.data.code && response.data.code == 200) {
  //   Store.commit("SET_ROLE_KEY_ITEMS", response.data.data);
  // } else {
  //   goLogin();
  //   return false;
  // }
});

export default router;
